'use strict'

class delcomment{
    constructor(){
        this.param = '/'
    }

    async post(c){
        let a = c.service.fun;
        let {comment_id,user_id,article_id} = JSON.parse(c.body)
        c.setHeader('content-type', 'text/html; charset=utf-8')
        let data1 =await a.sel('article_list',{'article_id':`${article_id}`},['poster_id'],c.service.pool)
        console.log(data1.rows[0])
        let {poster_id} = data1.rows[0]
        if(user_id == poster_id){
            a.del('comment_list',{'comment_id':`${comment_id}`,'comment_article_id':`${article_id}`},c.service.pool)
            c.send('success')
        }else{
            let data2 = await a.sel('comment_list',{'comment_id':`${comment_id}`},['comment_user_id'],c.service.pool)
            let {comment_user_id} = data2.rows[0]
            if(user_id == comment_user_id ){
                a.del('comment_list',{'comment_id':`${comment_id}`,'comment_user_id':`${user_id}`,'comment_article_id':`${article_id}`},c.service.pool)
                c.send('success')
            }else{
                c.send('fail')
            }
        }
        
    }
}


module.exports = delcomment
